package com.maxus.mini.common.utils;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class StringUtil {
	public static String getW(int num) {
		if (num > 9999) {
			double n = (double) num / 10000;

			String s = n + "W";
			if (s.contains(".")) {
				int index = s.lastIndexOf(".");
				return s.substring(0, index + 2) + "万";
			}
			return s;
		}

		return num + "";
	}

	/**
	 * 是否是空数组
	 * 
	 * @param arrayStr
	 * @return
	 */
	public static boolean isEmptyArray(String arrayStr) {
		if (StringUtils.isEmpty(arrayStr) || arrayStr.equals("[]")) {
			return true;
		}

		return false;
	}

	/**
	 * 
	 * @param ids
	 * @return
	 */
	public static List<Long> idsToLongList(String ids) {
		List<Long> list = new ArrayList<>();

		String[] idArr = ids.split(",");
		for (String string : idArr) {
			list.add(Long.parseLong(string));
		}

		return list;
	}

	/**
	 * 按照一定长度分隔数组
	 * 
	 * @param s
	 * @param len
	 * @return
	 */
	public static List<String> stringSpilt(String inputString, int byteLength) {
		List<String> list = new ArrayList<>();
		char[] chars = inputString.toCharArray();
		int inc = 0;
		int totalLength = 0;
		StringBuffer sb = new StringBuffer();
		for (char c : chars) {
			if (inc != byteLength) {
				sb.append(c);
				inc++;
			} else {
				inc = 0;
				list.add(sb.toString());
				sb.setLength(0);
			}
			
			totalLength++;
			if (chars.length == totalLength && chars.length % byteLength != 0) {
				list.add(sb.toString());
			}
		}

		return list;
	}
}
